package org.ellwood.core.common.result;

import lombok.Data;
import org.ellwood.core.common.enums.SocketChannelEnum;
import org.ellwood.core.utils.PageUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: ellwood-boot-pro
 * @PackageName: org.ellwood.core.common.entity.socket
 * @ClassName: SocketPageResult
 * @Description: // socker分页返回结果
 * @Author: Ellwood
 * @CreateDate: 2024/6/18 - 上午10:31
 * @Version: V1.0.0
 */
public class SocketPageResult<T> extends SocketResult<T> {

    public static <T> SocketPageResult<PageResult<T>> success(List<T> data) {
        SocketPageResult<PageResult<T>> apiResult = new SocketPageResult<>();
        apiResult.data = (data != null) ? PageUtils.getPageResult(data) : PageUtils.getPageResult(new ArrayList<>());
        return apiResult;
    }

    public static <T> SocketPageResult<PageResult<T>> success(SocketChannelEnum channel, PageResult<T> data) {
        SocketPageResult<PageResult<T>> apiResult = new SocketPageResult<>();
        apiResult.data = (data != null) ? data : PageUtils.getPageResult(new ArrayList<>());
        apiResult.channel = channel;
        return apiResult;
    }

    public static <T> SocketPageResult<PageResult<T>> success(SocketChannelEnum channel, List<T> data, Object param) {
        SocketPageResult<PageResult<T>> apiResult = new SocketPageResult<>();
        apiResult.channel = channel;
        apiResult.data = (data != null) ? PageUtils.getPageResult(data) : PageUtils.getPageResult(new ArrayList<>(), param);
        return apiResult;
    }

}
